<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Models\med_doctor;
use App\Models\users;
use App\Models\office;
use Illuminate\Database\Eloquent\SoftDeletes;
class nat extends Model
{
    use HasFactory;
    protected $table='nat';
    use SoftDeletes;
    protected $primaryKey='id';

    //关联患者
    public function users()
    {
        return $this->hasMany(users::class,'id','user_id')->select('id','name','id_card','phone');
    }
    //查询
    public function show($limit,$type,$name)
    {
        if ($type!=''){
            return self::with('users')->where('deleted_at',null)->where('type',$type)->paginate($limit);
        }
        //关联查询
        else if($name!=''){
            return self::with('users')
                ->wherehas('users',function ($res) use ($name){

                $res->where('name','like',"%$name%");

            })->paginate($limit);
        }
        else{
            return self::with('users')->where('deleted_at',null)->paginate($limit);
        }


    }
    //删除
    public function del($id)
    {
        return $this->find($id)->delete();
    }
}
